home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util4 / 0utils.lha / 0Utils / Touch.data < prev    next >
Text File  |  1995-09-05  |  3KB  |  140 lines

  1.  
  2. #ifdef TPLTER
  3.  
  4. Touch = {
  5.  
  6.  
  7.     SHORT = {{ touch files }};
  8.  
  9.     DESCRIPTION = {{
  10.     Touch checks the existance (via Lock) of files
  11.     and then either calls SetFileDate if they exist
  12.     or else creates new files
  13.  
  14.      RESULT
  15.     -/-
  16.     }};
  17.  
  18.     BUGS = {{
  19.     Touch breaks on the first error
  20.     }};
  21.  
  22.     SEEALSO = {{
  23.     C:SetDate, dos.library/Lock, dos.library/SetFileDate
  24.     }};
  25.  
  26.     HISTORY = {{
  27.     12-02-95 b_noll created (accidently deleted the source)
  28.     12-02-95 b_noll created
  29.     20-02-95 b_noll restructured source
  30.     21-02-95 b_noll added version/format-prefix/offset
  31.     20-03-95 b_noll added args diagnostics
  32.     19-08-95 b_noll created .data file
  33.     30-08-95 b_noll 1.3 added breakcheck
  34.     05-09-95 b_noll 1.4 added wildcard support
  35.     }};
  36.  
  37.  
  38.     Template = "FILE/A/M";
  39.     Arguments = {{
  40.     STRPTR *file;
  41.     }};
  42.  
  43.     userdata = {{
  44.     UBYTE  apb[sizeof (struct AnchorPath) + 8 + MAXPATHLEN];
  45.     }};
  46.  
  47.     version = "1.4";
  48.  
  49.     body = {{
  50.         int    cnt;
  51.         ULONG  error;
  52.         BPTR   bptr;
  53.         STRPTR name;
  54.         struct AnchorPath  *ap; // long aligned Anchor
  55.         struct DateStamp ds;
  56.  
  57.         retval = RETURN_OK;
  58.  
  59.         ap              = (void *)(((ULONG)(userdata->apb) + 7) & ~7);
  60.         ap->ap_Strlen     = MAXPATHLEN;
  61.         ap->ap_BreakBits  = 0;
  62.         ap->ap_FoundBreak = 0;
  63.         name = ap->ap_Buf;
  64.  
  65.         for (cnt = 0; argv->file[cnt] && !retval && !IS_BROKEN(); ++cnt) {
  66.         ap->ap_Flags = 0;
  67.  
  68.         for (error = MatchFirst(argv->file[cnt], ap); error == 0; error = MatchNext(ap)) {
  69.  
  70.             //if (retval = do_touch (ap->ap_Buf, gvars))
  71.             //      break;
  72.             retval = RETURN_ERROR;
  73.             if (bptr = Lock(name, SHARED_LOCK)) {
  74.             UnLock(bptr);
  75.  
  76.             DateStamp(&ds);
  77.             if (SetFileDate(name, &ds)) {
  78.                 retval = RETURN_OK;
  79.             } /* if */
  80.             } /* if */
  81.             if (retval)
  82.             break;
  83.  
  84.         } /* for wilds */
  85.         MatchEnd(ap);
  86.  
  87.         if (error != ERROR_NO_MORE_ENTRIES) { /* abnormal error */
  88.             if ((error == ERROR_OBJECT_NOT_FOUND) && !(ap->ap_Flags & APF_ITSWILD)) {
  89.  
  90.             /* ---- we leave this backdoor in order 2 B able 2 */
  91.             /*    delete icons whose files have been deleted */
  92.             /*    by just typing the filename (w/o .info)    */
  93.  
  94. //Printf ("doing NW %s\n", ap->ap_Buf);
  95.             //if (retval = do_touch (argv->file[cnt], gvars))
  96.             //    break;
  97.             if ((bptr = Open(argv->file[cnt], MODE_NEWFILE))) {
  98.                 Close(bptr);
  99.             } else
  100.                 retval = RETURN_ERROR;
  101.             } else {
  102.             retval = RETURN_ERROR;
  103.             } /* if real error */
  104.         } /* if possible error */
  105.         } /* for all patterns */
  106.     }};
  107.  
  108.  
  109. };
  110. #endif
  111.  
  112.     body = {{
  113.         int    i;
  114.         STRPTR name;
  115.  
  116.         retval = RETURN_OK;
  117.  
  118.         for (i = 0; (name = argv->file[i]) && !(BREAKCHECK()); ++i) {
  119.         BPTR   bptr;
  120.  
  121.         if (bptr = Lock(name, SHARED_LOCK)) {
  122.             struct DateStamp ds;
  123.             UnLock(bptr);
  124.  
  125.             DateStamp(&ds);
  126.             if (!SetFileDate(name, &ds)) {
  127.             retval = RETURN_ERROR;
  128.             break;
  129.             } /* if */
  130.         } else if ((IoErr() == ERROR_OBJECT_NOT_FOUND) && (bptr = Open(name, MODE_NEWFILE))) {
  131.             Close(bptr);
  132.         } else {
  133.             retval = RETURN_ERROR;
  134.             break;
  135.         } /* if */
  136.         } /* for */
  137.  
  138.     }};
  139.  
  140.